package com.onesports.intelligent.k12.polarlight.controller.operation;

import com.onesports.framework.kit.common.valid.Json;
import com.onesports.intelligent.k12.polarlight.common.utils.ResultUtil;
import com.onesports.intelligent.k12.polarlight.constant.ApiPathConstants;
import com.onesports.intelligent.k12.polarlight.domain.dto.common.IdDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.course.ClassMergeRuleDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.sys.ConfigDTO;
import com.onesports.intelligent.k12.polarlight.domain.vo.course.ClassMergeRuleVO;
import com.onesports.intelligent.k12.polarlight.domain.vo.sys.ConfigVO;
import com.onesports.intelligent.k12.polarlight.service.sys.ConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping(ApiPathConstants.SYS_CONFIG)
@Api(tags = "运营端-系统设置-配置管理")
@PreAuthorize("isAuthenticated()")
public class SysConfigController {

    private final ConfigService configService;

    @GetMapping("/list-class-merge-rule")
    @ApiOperation("拼班规则列表")
    public ResponseEntity<List<ClassMergeRuleVO>> listClassMergeRule(){
        return ResultUtil.success(configService.listClassMergeRule());
    }

    @PostMapping("/add-class-merge-rule")
    @ApiOperation("添加拼班规则")
    public ResponseEntity<Void> addClassMergeRule(@Json @RequestBody ClassMergeRuleDTO dto){
        configService.addClassMergeRule(dto);
        return ResultUtil.success();
    }

    @PostMapping("/edit-class-merge-rule")
    @ApiOperation("修改拼班规则")
    public ResponseEntity<Void> editClassMergeRule(@Json @RequestBody ClassMergeRuleDTO dto){
        configService.editClassMergeRule(dto);
        return ResultUtil.success();
    }

    @PostMapping("/del-class-merge-rule")
    @ApiOperation("删除拼班规则")
    public ResponseEntity<Void> addClassMergeRule(@Json @RequestBody IdDTO dto){
        configService.delClassMergeRule(dto.getId());
        return ResultUtil.success();
    }

    @PostMapping("/update")
    @ApiOperation("修改系统配置")
    public ResponseEntity<String> update(@Json @RequestBody ConfigDTO dto) {
        configService.updateByType(dto);
        return ResultUtil.success("修改成功");
    }


    @GetMapping("/list")
    @ApiOperation("查询系统配置列表")
    public ResponseEntity<List<ConfigVO>> list() {
        return ResultUtil.success(configService.queryList());
    }
}
